﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Reflection;

namespace UFrame.AutoQuote
{
    public class AutoQuoteTool  {
    
        public static bool IsHasAttribute<T>(Type type) where T : class
        {
            System.Object[] oList = type.GetCustomAttributes(typeof(T), true);
            foreach (var item in oList)
            {
                if ((item as T) != null)
                    return true;
            }

            return false;
        }

        public static bool IsSubClass<T>(Type subType)
        {
            
            return typeof(T).IsAssignableFrom(subType);
        }
        public static bool IsSubClass(Type parent,Type subType)
        {
            return parent.IsAssignableFrom(subType);
        }

        public static bool IsContainAttribute<T>(FieldInfo type)
        {
            var list = type.GetCustomAttributes(true);
            for (int i = 0; i < list.Length; i++)
            {
                if (list[i] is T)
                {
                    return true;
                }
            }

            return false;
        }

        public static bool IsContainAttribute<T>(Type type)
        {
            var list = type.GetCustomAttributes(true);
            for (int i = 0; i < list.Length; i++)
            {
                if (list[i] is T)
                {
                    return true;
                }
            }

            return false;
        }

    }
}



